/**
 * 
 */
package com.bagtrack.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.bagtrack.dao.IFlightDAO;
import com.bagtrack.model.Flight;


/**
 * @author Brian Boyle
 * Nov 14, 2011
 */
public class FlightDAOImpl extends HibernateDaoSupport implements IFlightDAO {


    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Flight> selectActiveFlights() {
        Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
        session.beginTransaction();
        return session.createCriteria(Flight.class).add(Restrictions.eq("status", Flight.IN_COMPLETE_STATUS)).list();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Flight selectFlightById(Long id) {
        Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
        session.beginTransaction();
        return (Flight) session.createCriteria(Flight.class).add(Restrictions.eq("id", id)).uniqueResult();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void saveFlight(Flight flight) {
        getHibernateTemplate().save(flight);
    }


}
